package com.eric.test.list;

import org.checkerframework.checker.units.qual.A;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @description:
 * @author: liuBing
 * @create: 2024-06-13 12:24
 **/
public class ListMethod {

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        List<String> listTwo = Arrays.asList("1", "2", "3");


        list.add("a");
        list.add(1, "b");

        list.addAll(listTwo);
        list.addAll(3, listTwo);

        System.out.println(list);

        String s = list.get(0);
        System.out.println(s);

        // 包含某个元素
        boolean a = list.contains("a");
        System.out.println(a);

        // 包含其他数组
        boolean b = list.containsAll(listTwo);
        System.out.println(b);

        // 获取某个元素的下表
        int i = list.indexOf("1");
        System.out.println("indexOf: " + i);

        // 去掉数组种第一个为 1 的元素
        list.remove("1");
        System.out.println("remove: " + list);

        // 去掉所有 2 和 3
        List<String> listThree = List.of("2", "3");
        list.removeAll(listThree);
        System.out.println("removeAll: " + list);

        boolean isEmpty = list.isEmpty();
        System.out.println("isEmpty: " + isEmpty);

        int size = list.size();
        System.out.println("size: " + size);

        list.clear();
        System.out.println(list);

    }
}
